package com.ankicoo.practice.daily;

import java.util.Arrays;

/**
 * Description:1620. 网络信号最好的坐标
 *
 * @author : QCYANG
 * @date : 2022/11/2 10:36
 */
public class LC1620 {
    public static int[] bestCoordinate(int[][] towers, int radius) {
        int xMax = 0, yMax = 0;
        for (int[] tower : towers) {
            int x = tower[0], y = tower[1];
            xMax = Math.max(xMax, x);
            yMax = Math.max(yMax, y);
        }
        int resultX = 0, resultY = 0;
        int maxQuality = 0;
        for (int x = 0; x <= xMax; x++) {
            for (int y = 0; y <= yMax; y++) {
                int quality = 0;
                for (int[] tower : towers) {
                    double length =
                            Math.sqrt((tower[0] - x) * (tower[0] - x) + (tower[1] - y) * (tower[1] - y));
                    if (length <= radius) {
                        quality += (int)Math.floor(tower[2]/(1+length));
                    }
                }
                if (quality > maxQuality) {
                    resultX = x;
                    resultY = y;
                    maxQuality = quality;
                }
            }
        }
        return new int[]{resultX, resultY};
    }

    public static void main(String[] args) {
        int[][] tower = new int[][] {{2,1,9},{0,1,9}};
        int radius = 2;
        int[] ints = bestCoordinate(tower, radius);
        for (int i : ints) {
            System.out.println(i);
        }
    }
}
